import Vuex from 'vuex'

const modulesFiles = import.meta.glob('./modules/*.ts', { eager: true })
const modules = Object.keys(modulesFiles).reduce((p, n) => {
  const moduleName = n.replace(/^\.\/modules\/(.+)\.ts$/, '$1')
  const value = modulesFiles[n]
  p[moduleName] = value.default
  return p
}, {})
console.log(modules)

interface State {
  token: string
  userInfo: Object
  safeAreaBottom: number
}

const getters = {}
const state: State = {
  token: '',
  userInfo: {},
  safeAreaBottom: 0
}
const mutations = {
  setToken(state, payload: string) {
    state.token = payload
  },
  SET_USERINFO(state, payload: Object) {
    state.userInfo = payload
  },
  setSafeAreaBottom(state, payload) {
    state.safeAreaBottom = payload
  }
}

const actions = {}

const store = new Vuex.Store({
  getters,
  state,
  mutations,
  actions,
  modules
})

export default store
